import React, { Component } from 'react';
import { Grid, Loading, Tab, Card } from '@icedesign/base';
import { Link } from 'react-router-dom';
// import { GetUrlParam, LoginReq } from '../../baseConfig';
import DailyOverview from '../DailyOverview/DailyOverview';
import SearchPage from '../SearchPage/SearchPage';
import AnalysisPage from '../AnalysisPage/AnalysisPage';
import NewList from '../../components/NewsList'

import './PublicOpinion.scss';

// var echarts = require('echarts');
const { Row, Col } = Grid;
const TabPane = Tab.TabPane;

export default class PublicOpinion extends Component {
  static displayName = 'PublicOpinion';

  constructor(props) {
    super(props);
    this.state = {
      activeKey: 0,
      lazyLoad:true,
      NewListData:{
        timeIndexSelcet:'',
        originType:0,
        similarMerge:0,
        sensitivityType:0,
        order:0
      },
      newsid:'',
      leftURL:`${global.constants.GOLDEYEGETHOST}cattle/opinion_list?secu_code=${this.GetUrlParam("secu_code")}&originType=3,4,5,6,7,8,9,10,11,12&similarMerge=1`,
      centerURL:`${global.constants.GOLDEYEGETHOST}cattle/opinion_list?secu_code=${this.GetUrlParam("secu_code")}&originType=1&sensitivityType=2&order=3&similarMerge=1`,
      rightURL:`${global.constants.GOLDEYEGETHOST}cattle/opinion_list?secu_code=${this.GetUrlParam("secu_code")}&originType=2&order=3&similarMerge=1`,
    };
  }

  TidChange = (key) => {
    // console.log("key",key)
    localStorage.setItem("sid",key)
    this.setState({
      activeKey:key,
    })
    // console.log("props",localStorage.getItem("NewsListData"))
  }

  // More = (timeIndexSelcet,originType,similarMerge,sensitivityType,order) => {
  //   // console.log(comblineflg);
  //   // localStorage.setItem("sid",1)
  //   this.setState({
  //     NewListData:{
  //         timeIndexSelcet: timeIndexSelcet,
  //         originType: originType,
  //         similarMerge: similarMerge,
  //         sensitivityType: sensitivityType,
  //         order: order
  //       },
  //     },() => {
  //       localStorage.setItem("NewListData",JSON.stringify(this.state.NewListData))
  //       window.location.href = window.location.href.split('/#/')[0]+`/#/Evaluate/PublicOpinion?originType=${originType}&similarMerge=${similarMerge}&type=1&secu_code=${this.GetUrlParam("secu_code")}`;
  //       this.setState({
  //         activeKey: 1
  //       })
  //     })
  //   // console.log("NewListData",JSON.parse(localStorage.getItem("NewListData")))
  // }

  MoreHot = (timeIndexSelcet,originType,similarMerge,sensitivityType,order) => {
    // console.log(comblineflg);
    // localStorage.setItem("sid",1)
    this.setState({
      NewListData:{
          timeIndexSelcet: timeIndexSelcet,
          originType: originType,
          similarMerge: similarMerge,
          sensitivityType: sensitivityType,
          order: order
        },
      },() => {
        localStorage.setItem("NewListData",JSON.stringify(this.state.NewListData));
        // window.location.href = `http://192.168.1.190:4447/#/Evaluate/PublicOpinion?originType=${originType}&comblineflg=${comblineflg}&options=${options}&orderBy=${orderBy}&type=1&secu_code=${this.GetUrlParam("secu_code")}`
        // console.log(window.location.href.split('/#/')[0]+ `/#/Evaluate/PublicOpinion?originType=${originType}&comblineflg=${comblineflg}&options=${options}&orderBy=${orderBy}&type=1&secu_code=${this.GetUrlParam("secu_code")}`)
        window.location.href = window.location.href.split('/#/')[0]+ `/#/Evaluate/PublicOpinion?originType=${originType}&similarMerge=${similarMerge}&sensitivityType=${sensitivityType}&order=${order}&type=1&secu_code=${this.GetUrlParam("secu_code")}`
        location.reload(true)
        this.setState({
          activeKey: 1
        })
      })
    // console.log("NewListData",JSON.parse(localStorage.getItem("NewListData")))
  }

  componentDidMount(){
    if(this.GetUrlParam("type") == "1"){
      this.setState({
        activeKey:1
      })
    }else{
      this.setState({
        activeKey:0
      })
    }
  }

  GetUrlParam(paraName) {
  　var url = document.location.toString();
  　var arrObj = url.split("?");
　　　if (arrObj.length > 1) {
　　　　　var arrPara = arrObj[1].split("&");
　　　　　var arr;
　　　　　for (var i = 0; i < arrPara.length; i++) {
　　　　　　　arr = arrPara[i].split("=");
　　　　　　　if (arr != null && arr[0] == paraName) {
　　　　　　　　　return arr[1];
　　　　　　　}
　　　　　}
　　　　　return "";
　　　}
　　　else { return ""; }
  }

  render() {
    // const {leftURL,centerURL,rightURL} = this.state
    return (
      <div>
        <Tab prefix="pre-" activeKey={this.state.activeKey} defaultActiveKey="0" onChange={this.TidChange.bind(this)} lazyLoad={this.state.lazyLoad}>
          <TabPane tab="每日概述" key="0">
            <DailyOverview />
            <Row wrap gutter="20">
              <Col s="8" xxs="24">
                <Card
                  title="热点信息"
                  style={styles.container}
                  extra={
                    <div className="mo" onClick={this.MoreHot.bind(this,'24小时','3,4,5,6,7,8,9,10,11,12',1,null,null)}>更多</div> 
                    // <a className="mo" href={`https://gdpage.cfbond.com/gdBeta2.0/#/Evaluate/PublicOpinion?originType=3,4,5,6,7,8,9,10,11,12&comblineflg=1&type=1&secu_code=${this.GetUrlParam("secu_code")}`}>更多</a>
                    // <div style={styles.mo} onClick={this.More.bind(this,'24小时','3,4,5,6,7,8,9,10,11,12',1,'','')}>更多</div> 
                  }
                  bodyHeight="auto">
                  <NewList dataURL={this.state.leftURL} secuCode={this.GetUrlParam("secu_code")} />
                </Card>
              </Col>
              <Col s="8" xxs="24">
                <Card
                  title="敏感信息"
                  style={styles.container}
                  extra={
                  // <Link to={`/Evaluate?machineCode=${this.props.machineCode}&timeIndexSelcet=24小时&options=2&comblineflg=1&originType=1`}>更多</Link>
                  <div className="mo" onClick={this.MoreHot.bind(this,'24小时',"1",1,2,null)}>更多</div>
                  // <a className="mo" href={`https://gdpage.cfbond.com/gdBeta2.0/#/Evaluate/PublicOpinion?originType=1&comblineflg=1&options=2&type=1&secu_code=${this.GetUrlParam("secu_code")}`}>更多</a>
                  // <div style={styles.mo} onClick={this.More.bind(this,'24小时',"1",1,2,'')}>更多</div> 
                  }
                  bodyHeight="auto">
                  <NewList dataURL={this.state.centerURL} secuCode={this.GetUrlParam("secu_code")} />
                </Card>
              </Col>
              <Col s="8" xxs="24">
                <Card title="热点微博"
                  style={styles.container}
                  extra={<div className="mo" onClick={this.MoreHot.bind(this,'24小时',"2",1,1,3)}>更多</div>}
                  bodyHeight="auto">
                  <NewList dataURL={this.state.rightURL} secuCode={this.GetUrlParam("secu_code")} />
                </Card>
              </Col>
            </Row>
          </TabPane>
          <TabPane tab="舆情监测" key="1">
            <SearchPage NewListData={this.state.NewListData} machineCode={this.GetUrlParam("secu_code")} />
          </TabPane>
          <TabPane tab="舆情分析" key="2">
            <AnalysisPage />
          </TabPane>
        </Tab>
      </div>
    );
  }
}


const styles = {
  container: {
    // height: 316,
    width:'100%',
    borderRadius:'0',
    boxShadow:'none',
  },
  reviewRatingWrapper: {
    padding: '20px 0',
  },
  mo: {
    cursor:'pointer'
  },
  reviewRatingDesc: {
    color: '#999',
    textAlign: 'center',
  },
  reviewRating: {
    display: 'flex',
    alignItems: 'center',
    justifyContent: 'center',
  },
  reviewRatingScore: {
    fontSize: 36,
    position: 'absolute',
    right: 'calc(100% + 20px)',
  },
  reviewRatingIcon: {
    position: 'relative',
    margin: '0 20px',
    display: 'flex',
    alignItems: 'center',
    justifyContent: 'center',
  },
  reviewRatingRatePositive: {
    fontSize: 26,
    color: '#2ecc71',
    position: 'absolute',
    left: 'calc(100% + 20px)',
  },
  reviewRatingRateNegative: {
    fontSize: 26,
    color: '#e74c3c',
    position: 'absolute',
    left: 'calc(100% + 20px)',
  },
  reviewRatingIconPositive: {
    color: '#2ecc71',
  },
  reviewRatingIconNegative: {
    color: '#e74c3c',
  },
  reviewRatingDivideLine: {
    borderTop: '1px solid #eee',
    width: 100,
    margin: '0 auto',
  },
  reviewTargetProgressWrapper: {
    padding: '30px 0 20px 0',
    display: 'flex',
    justifyContent: 'center',
  },
  reviewRatingGoalDesc: {
    textAlign: 'center',
  },
  reviewLeaderboardItem: {
    marginTop: 10,
    display: 'flex',
    alignItems: 'center',
    position: 'relative',
    justifyContent: 'space-between',
  },
  reviewLeaderboardItemAvatar: {
    borderRadius: '50%',
    overflow: 'hidden',
    display: 'inline-block',
    marginRight: 15,
  },
  reviewLeaderboardItemAvatarImg: {
    display: 'block',
  },
  reviewLeaderboardItemName: {
    flex: 1,
  },
}